import requests

from api.base import Login


class MerchantProduct(Login):

    def merchant_product_list(self, type=1, keywords=None):
        """

        :param type: 1-出售 2、仓库 3、售罄
        :return:
        """
        data = {
            "url": "/api/admin/merchant/product/list",
            "method": "GET",
            "headers": {'authori-zation': self.merchant_token},
            "params": {
                'page': '1',
                'limit': '20',
                'cateId': '',
                'keywords': "panda",
                'type': 1,
                'temp': '1723616061',
            }
        }

        return self.send_merchant_request("商品查询", data)

    def merchant_product_up(self, up_id):
        data = {
            "url": f"/api/admin/merchant/product/up/{up_id}",
            "method": "POST",
            "headers": {'authori-zation': self.merchant_token},
            "json": {

            }
        }

        return self.send_merchant_request("商品上架", data)

    def merchant_product_sava(self, name: str, price: int):
        """

        :param name: 商品名称
        :param price: 商品价格
        :return:
        """
        data = {
            "url": "/api/admin/merchant/product/save",
            "method": "POST",
            "headers": {'authori-zation': self.merchant_token, 'content-type': 'application/json'},
            "json": {
                'image': 'https://crmebjavamer.oss-cn-beijing.aliyuncs.com/crmebimage/public/store/2024/08/09/329e096ada794a27993d7c1a9b3e6dfe1izzcb4g22.png',
                'sliderImages': [
                    'https://crmebjavamer.oss-cn-beijing.aliyuncs.com/crmebimage/public/store/2024/08/09/329e096ada794a27993d7c1a9b3e6dfe1izzcb4g22.png',
                ],
                'sliderImage': '["https://crmebjavamer.oss-cn-beijing.aliyuncs.com/crmebimage/public/store/2024/08/09/329e096ada794a27993d7c1a9b3e6dfe1izzcb4g22.png"]',
                'name': name,
                'intro': '为如果他回过头果然非凡微软同仁堂过热而',
                'keyword': '而无法认同和加热',
                'cateIds': [
                    859,
                ],
                'cateId': '859',
                'unitName': '嘎嘎嘎嘎嘎嘎嘎嘎',
                'sort': 1,
                'isShow': False,
                'tempId': 285,
                'attrValue': [
                    {
                        'image': 'https://crmebjavamer.oss-cn-beijing.aliyuncs.com/crmebimage/public/store/2024/08/09/329e096ada794a27993d7c1a9b3e6dfe1izzcb4g22.png',
                        'price': price,
                        'vipPrice': 0.01,
                        'cost': 541,
                        'otPrice': 8765,
                        'stock': 234,
                        'barCode': '2',
                        'weight': 0.01,
                        'volume': 0.01,
                        'brokerage': 0,
                        'brokerageTwo': 0,
                        'cdkeyId': None,
                        'cdkeyLibraryName': '',
                        'expand': '',
                        'attrValue': '{"规格":"默认"}',
                        'productId': 0,
                    },
                ],
                'attr': [
                    {
                        'attrName': '规格',
                        'attrValues': '默认',
                        'id': 0,
                    },
                ],
                'selectRule': '',
                'isSub': False,
                'isPaidMember': False,
                'content': '',
                'specType': False,
                'couponIds': [],
                'coupons': [],
                'categoryId': 177,
                'guaranteeIds': '',
                'guaranteeIdsList': [],
                'brandId': 0,
                'type': 0,
                'isAutoSubmitAudit': False,
                'isAutoUp': False,
            },
        }

        return self.send_merchant_request("垃圾回收站", data)

    def merchant_product_recycle(self, id_data: list[int]):
        data = {
            "url": "/api/admin/merchant/product/batch/recycle",
            "method": "post",
            "headers": {'authori-zation': self.merchant_token,
                        'content-type': 'application/json'},
            "json": {
                'idList': id_data
            }
        }
        return self.send_merchant_request("清空回收站", data)

    def merchant_product_delete(self, id_data: list[int]):
        data = {
            "url": "/api/admin/merchant/product/batch/delete",
            "method": "post",
            "headers": {'authori-zation': self.merchant_token,
                        'content-type': 'application/json', },
            "json": {
                'idList': id_data
            }
        }
        return self.send_merchant_request(data)


if __name__ == '__main__':
    print(MerchantProduct().merchant_product_delete())
